package classloader;

import java.lang.reflect.Method;

public class TestClassIdentity {

	public void testClassIdentiti() {
		String classDataRootPath = System.getProperty("user.dir")+"/resource";
		FileSystemClassLoader fscl1 = new FileSystemClassLoader(
				classDataRootPath);
		FileSystemClassLoader fscl2 = new FileSystemClassLoader(
				classDataRootPath);
		String className = "com.example.Sample";
		try {
			Class<?> class1 = fscl1.loadClass(className);
			Object obj1 = class1.newInstance();
			Class<?> class2 = fscl2.loadClass(className);
			Object obj2 = class2.newInstance();

			System.out.println(class1.getClassLoader());
			System.out.println(class1.getClassLoader().getParent());
			System.out.println(class2.getClassLoader());

			Method setSampleMethod = class1.getMethod("setSample",
					java.lang.Object.class);
			setSampleMethod.invoke(obj1, obj2);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("end");
	}

	public static void main(String[] args) {
		TestClassIdentity t = new TestClassIdentity();
		t.testClassIdentiti();
	}

}
